use TeO, clear

// standardize items
foreach x in relimp r_ostent r_miam r_impedu r_culte feelfbpl feelfrench feelmorefor seenasfrench homeinfrance french_fam french_sp french_kids {
	sum `x', det
	gen `x'_st=(`x'-r(mean))/r(sd)
}

egen avg_rel=rowmean(relimp_st r_ostent_st r_miam_st r_impedu_st r_culte_st)

egen avg_assim=rowmean(feelfrench_st seenasfrench_st homeinfrance_st)

egen avg_lan=rowmean(french_fam french_sp french_kids)

// Predicted devoutness/assimilation using predictors identified by lasso2 
reg avg_lan muslimm frenchm frenchbirth frenchathome turkeyf roafricaf 
predict lingassim_2, xb

reg avg_rel muslimm frenchm 
predict devoutness_avg_2, xb

reg avg_assim muslimm frenchathome roafricaf 
predict assimilation_2, xb

//DID
estimates clear

reg feelfrench i.birthyear##c.devoutness_avg_2 i.religion##c.devoutness_avg_2 tmuslim devoutness_avg_2  interm##c.devoutness_avg_2 if bpl=="1101" &female==1&fbpl!=1101  &mbpl!=1101, cl(religion)
eststo m1

reg feelfrench i.birthyear##c.assimilation_2 i.religion##c.assimilation_2 tmuslim assimilation_2  interm##c.assimilation_2 if bpl=="1101" &female==1&fbpl!=1101  &mbpl!=1101, cl(religion)
eststo m4

reg feelfrench i.birthyear##c.lingassim_2 i.religion##c.lingassim_2 tmuslim lingassim_2  interm##c.lingassim_2 if bpl=="1101" &female==1&fbpl!=1101  &mbpl!=1101, cl(religion)
eststo m7

reg avg_rel i.birthyear##c.devoutness_avg_2 i.religion##c.devoutness_avg_2 tmuslim devoutness_avg_2  interm##c.devoutness_avg_2 if bpl=="1101" &female==1, cl(religion)
eststo m3

reg avg_rel i.birthyear##c.assimilation_2 i.religion##c.assimilation_2 tmuslim assimilation_2  interm##c.assimilation_2 if bpl=="1101" &female==1, cl(religion)
eststo m6

reg avg_rel i.birthyear##c.lingassim_2 i.religion##c.lingassim_2 tmuslim lingassim_2  interm##c.lingassim_2 if bpl=="1101" &female==1, cl(religion)
eststo m9

esttab m* using "TableA6.csv", star(+ 0.1 * 0.05 ** 0.01 *** 0.001) replace ///
		cells(b(fmt(a3) star) se(par)) stats(N r2)  ///
		keep(1.interm 1.interm#c*) 
